package com.example.teacher.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.apiservice.client.StudentClient;
import com.example.common.domain.Result;
import com.example.common.domain.dto.HomeworkDto;
import com.example.common.domain.pojo.HomeworkStudent;
import com.example.common.domain.vo.PageWithAnswer;
import com.example.common.domain.vo.QuestionWithAnswerVO;
import com.example.teacher.Service.HomeworkService;
import com.example.teacher.Service.HomeworkStudentService;
import com.example.teacher.domain.vo.HomeworkSatatus;
import com.example.teacher.domain.vo.HomeworkSatatusVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@Api(value = "老师端批改作业接口", description = "作业方面的")
@RestController
@RefreshScope//时时刷新配置信息
@Slf4j  //日志  log.info("登录日志测试：");
@RequestMapping("/teachers/correction")
@RequiredArgsConstructor
public class WorkController {
    @Autowired
    private HomeworkService homeworkService;
    @Autowired
    private HomeworkStudentService homeworkStudentService;
    @Autowired
    private StudentClient studentClient;


    @ApiOperation("查询具体作业状态")         //完成人数、作业完成状态、作业完成百分比,及批改状态||批后的平均分，最高分，最低分，分数排行
    @GetMapping("/getHomeworkStatus/{homeworkId}")
    public Result<HomeworkSatatus> getHomeworkStatus(@PathVariable String homeworkId) {
        return Result.success(homeworkStudentService.getHomeworkStatus(homeworkId));
    }

    @ApiOperation("查询具体作业状态2")         //完成人数、作业完成状态、作业完成百分比,及批改状态||批后的平均分，最高分，最低分，分数排行
    @GetMapping("/getHomeworkStatus2/{homeworkId}/{type}")
    public Result<HomeworkSatatusVo> getHomeworkStatus2(@PathVariable String homeworkId,
                                                        @PathVariable String type,
                                                        @RequestParam(defaultValue = "1") Integer pageNum,
                                                        @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(homeworkStudentService.getHomeworkStatus2(homeworkId, pageNum, pageSize, type));
    }

    @ApiOperation("返回前端学生作业状态的列表")  //作业是否批改，批改后的分数
    @PostMapping("/getHomeworkByStudentPage/{homeworkId}")
    public Result<Page<HomeworkStudent>> getHomeworkByStudent(@PathVariable String homeworkId,
                                                              @RequestParam(defaultValue = "1") Integer pageNum,
                                                              @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(homeworkStudentService.getHomeworkByStudent(homeworkId, pageNum, pageSize));
    }


    @ApiOperation("查询具体学生写的作业")
    @PostMapping("/getHomeworkByStudentId")
    Result<PageWithAnswer<QuestionWithAnswerVO>> getHomeworkByStudentId(@RequestBody HomeworkDto h) {
        return studentClient.getHomework(h);
    }

    @ApiOperation("修改学生单次作业")
    @PostMapping("/modifyHomeworkOne")
    public Result<String> modifyHomeworkOne(@RequestBody HomeworkStudent homeworkStudent) {
        return Result.success(homeworkStudentService.updateById(homeworkStudent) ? "修改成功" : "修改失败");
    }


//    @ApiOperation("ai批改多选")
//    @PostMapping("/AiModifyHomework")


}
